home *** CD-ROM | disk | FTP | other *** search
- ;void string_string(sub_strg,return_strg,length);
- ; char *sub_strg,*return_strg;
- ; unsigned short length;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _string_string
- _string_string proc near
- push bp ;
- mov bp,sp ;set up stack frame
- push di ;
- push si ;
- push ds ;save DS
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: mov _error_code,1 ;1 = error
- cmp _memory_model,2 ;data near or far?
- jb L1 ;jump if near
- les di,dword ptr[bp+8] ;ES:DI pts to return string
- lds si,dword ptr[bp+4] ;DS:SI pts to substring
- add bp,4 ;add 4 to BP since dword ptr
- jmp short L2 ;
- L1: mov di,[bp+6] ;NEAR case
- mov si,[bp+4] ;
- mov ax,ds ;ES = DS
- mov es,ax ;
- L2: mov byte ptr es:[di],0 ;return null string if error
- mov bx,si ;save substring start pt
- mov cx,[bp+8] ;return string length
- jcxz L5 ;quit if null
- cmp byte ptr[si],0 ;test for null substring
- je L5 ;quit if null
- L3: mov al,[si] ;get a char
- inc si ;forward for next time
- cmp al,0 ;end of string?
- jne L4 ;jump if so
- mov si,bx ;back to start of substrg
- jmp short L3 ;loop back
- L4: mov es:[di],al ;else write the char
- inc di ;forward return_string ptr
- loop L3 ;go do next
- mov byte ptr es:[di],0 ;terminating null
- pop ds ;restore DS
- dec _error_code ;0 = no error
- jmp short L6 ;jump ahead
- L5: pop ds ;terminate with error
- L6: pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _string_string ENDP
- _TEXT ENDS
- END